/**
 * Level2Navigator.jsx
 * 二级导航
 *
 * created by qiuwei
 * version 1.0.0
 * 2016年03月19日
 */

import React from 'react';
import cx from 'classnames';

import * as Level2NavigatorStyle from './Level2Navigator.less';

export default class Level2Navigator extends React.Component {
	static propTypes = {
		items: React.PropTypes.array,
		onChange: React.PropTypes.func,
	};

	constructor(props) {
		super(props);
	}

	handleViewChange = (view) => {
		let { onChange } = this.props;
		onChange && onChange(view);
	};

	render() {
		let { items, selectedItem } = this.props;

		let nodes = items.reduce((nodes, n, index) => {
			nodes.push(
				<span key={index} className={cx({ 'checked': selectedItem == n.ID })} 
					onClick={() => this.handleViewChange(n.ID)}>{n.label}</span>);
			return nodes;
		}, []);

		return (
			<div className={Level2NavigatorStyle.lv2Nagivator}>
				{nodes}
			</div>
		);
	}
}